package com.example.administrator.managesystem.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.utils.StatusBarUtil;
import com.example.administrator.managesystem.view.StateLayout;


/**
 * BaseFragment是所有Fragment的基类，把一些公共的方法放到里面，如基础样式设置，权限封装，网络状态监听等
 */
public abstract class BaseFragment extends Fragment {
    protected abstract void initView(View view, Bundle savedInstanceState);
    protected StateLayout stateLayout;

    //获取布局文件ID
    protected abstract int getLayoutId();


       @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //状态栏
        // StatusBarUtil.setWindowStatusBarColor(getActivity(), R.color.color_53);
        View view = inflater.inflate(getLayoutId(), container, false);
        initView(view, savedInstanceState);
        doBusiness();


        return view;
    }

//
//    @Override
//    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//        //防止Fragment重复加载
//        if (stateLayout == null) {
//            // 说明这个Fragemnt的onCreateView方法是第一次执行
//            View view = inflater.inflate(getLayoutId(), container, false);
//            initView(view, savedInstanceState);
//            //对Fragment展示的布局进一步封装
//            stateLayout = StateLayout.newInstance(getActivity(), view);
//           doBusiness();
//        } else {
//            ViewGroup parent = (ViewGroup) stateLayout.getParent();
//            if (parent != null) {
//                parent.removeView(stateLayout);
//            }
//        }
//
//        return stateLayout;
//    }

    protected abstract void doBusiness();



    @Override
    public void onDestroy() {
        super.onDestroy();

    }

    /***
     * 跳转
     */
    public void gotoActivity(Class<?> toactivity,boolean close){
        Intent intent=new Intent(getActivity(),toactivity);
        startActivity(intent);
        if(close){
            getActivity().finish();
        }
    }
}
